| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | Static Public Member Functions | List of all members
nkGraphics::Buffer Class Referenceabstract

A buffer that will reside on the GPU. More...

Inheritance diagram for nkGraphics::Buffer:

## Public Member Functions
virtual | ~Buffer ()
unsigned int | getElementByteSize () const
unsigned int | getElementCount () const
unsigned int | getTotalByteSize () const
virtual BUFFER_USAGE | getUsage () const =0
virtual BUFFER_BIND_FLAG | getBindFlag () const =0
virtual BUFFER_CPU_ACCESS_FLAG | getCpuAccessFlag () const =0
virtual RESOURCE_MISC_FLAG | getMiscFlag () const =0
void | setCpuData (nkMemory::BufferView<> data)
void | setCpuDataCopy (nkMemory::BufferView<> data)
void | setCpuDataForward (nkMemory::Buffer &&data)
virtual void | freeCpuData ()
virtual void | setElementByteSize (unsigned int value)
virtual void | setElementCount (unsigned int value)
virtual void | setUsage (BUFFER_USAGE value)=0
virtual void | setBindFlag (BUFFER_BIND_FLAG value)=0
virtual void | setCpuAccessFlag (BUFFER_CPU_ACCESS_FLAG value)=0
virtual void | setMiscFlag (RESOURCE_MISC_FLAG value)=0
virtual void | copyParams (const Buffer &other)
virtual MapResult | map (const MapRequestDescriptor &requestDesc)=0
virtual void | unmap (const UnmapRequestDescriptor &requestDesc)=0
virtual void | gpuCopyFrom (Buffer &other, const ResourceGpuCopyDescriptor &descriptor)=0
virtual void | prepareForShaderResourceUsage (bool value=true)
virtual void | prepareForComputeResourceUsage (bool value=true)
virtual void | prepareForOutputStreamUsage (bool value=true)
virtual void | exportClassToTree (nkExport::Node *rootNode) override
virtual void | importClassFromTree (nkExport::Node *rootNode) override
Buffer & | operator= (const Buffer &)=delete
Public Member Functions inherited from nkGraphics::ShaderResource
virtual | ~ShaderResource ()
Public Member Functions inherited from nkGraphics::Resource
virtual | ~Resource ()
bool | isReadyForRendering () const
bool | isUnloaded () const
RESOURCE_LOAD_STATE | getLoadState () const
nkMemory::StringView | getPath () const
RESOURCE_TYPE | getTypeName () const
nkMemory::StringView | getName () const
System * | getSystem () const
bool | getHidden () const
bool | getGpuUploadCanBeDeferred () const
virtual void | setPath (nkMemory::StringView value)
void | setName (nkMemory::StringView value)
void | setHidden (bool value)
void | setGpuUploadCanBeDeferred (bool value)
virtual bool | load ()=0
virtual void | unload ()=0
Public Member Functions inherited from nkExport::Exportable
| Exportable () noexcept
virtual | ~Exportable ()

## Static Public Member Functions
static nkMemory::UniquePtr< Buffer > | create (System *system=nullptr)

## Detailed Description

A buffer that will reside on the GPU.

Used as the basic memory holder to push data to the GPU. Each renderer will have its own implementation to adapt it to the API it targets.

See BufferManager::createOrRetrieve() or Buffer::create() for instantiation.

## Constructor & Destructor Documentation

## ◆ ~Buffer()

virtual nkGraphics::Buffer::~Buffer | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

## ◆ getElementByteSize()

unsigned int nkGraphics::Buffer::getElementByteSize | ( |  | ) | const

Returns
  An element's byte size within the buffer.

## ◆ getElementCount()

unsigned int nkGraphics::Buffer::getElementCount | ( |  | ) | const

Returns
  The element count within the buffer.

## ◆ getTotalByteSize()

unsigned int nkGraphics::Buffer::getTotalByteSize | ( |  | ) | const

Returns
  The final byte size of the buffer. Computed as elementByteSize * elementCount.

## ◆ getUsage()

virtual BUFFER_USAGE nkGraphics::Buffer::getUsage | ( |  | ) | const
| pure virtual

Returns
  The usage declared for the buffer.

## ◆ getBindFlag()

virtual BUFFER_BIND_FLAG nkGraphics::Buffer::getBindFlag | ( |  | ) | const
| pure virtual

Returns
  The binding declared for the buffer.

## ◆ getCpuAccessFlag()

virtual BUFFER_CPU_ACCESS_FLAG nkGraphics::Buffer::getCpuAccessFlag | ( |  | ) | const
| pure virtual

Returns
  The cpu access flag declared for the buffer.

## ◆ getMiscFlag()

virtual RESOURCE_MISC_FLAG nkGraphics::Buffer::getMiscFlag | ( |  | ) | const
| pure virtual

Returns
  Any misc flag set on the buffer.

## ◆ setCpuData()

void nkGraphics::Buffer::setCpuData | ( | nkMemory::BufferView<> | data | ) |

Sets the CPU data to upload to the gpu buffer during load.

Parameters

  data | The data to provide.

Remarks
  This version will make a view over the data to avoid copying it locally. Client code should ensure data is available during load of the Buffer, by keeping it alive until its state is RESOURCE_LOAD_STATE::LOADED. Buffer will not be considered owner of given data.

## ◆ setCpuDataCopy()

void nkGraphics::Buffer::setCpuDataCopy | ( | nkMemory::BufferView<> | data | ) |

Sets the CPU data to upload to the gpu buffer during load.

Parameters

  data | The data to provide.

Remarks
  This version will make a local copy of the data, into a local CPU buffer owned by the resource. Calling this version ensure the internal managing of the attached memory will be made by the resource itself.

## ◆ setCpuDataForward()

void nkGraphics::Buffer::setCpuDataForward | ( | nkMemory::Buffer && | data | ) |

Sets the CPU data to upload to the gpu buffer during load.

Parameters

  data | The data to provide.

Remarks
  This version will make make a local buffer and move provided data to it, invalidating given data. Calling this version ensure the internal managing of the attached memory will be made by the resource itself, while avoiding the copy overhead.

## ◆ freeCpuData()

virtual void nkGraphics::Buffer::freeCpuData | ( |  | ) |
| virtual

Frees the CPU data holding structures and, if owning them, local shadow CPU buffers.

Remarks
  Renderers are smart enough to know when data should be freed. After a call to load(), this function can be called right away and the buffer will delete it when it can.

## ◆ setElementByteSize()

virtual void nkGraphics::Buffer::setElementByteSize | ( | unsigned int | value | ) |
| virtual

Sets the size of an element within the buffer.

Parameters

  value | The byte size an element will have in the buffer.

## ◆ setElementCount()

virtual void nkGraphics::Buffer::setElementCount | ( | unsigned int | value | ) |
| virtual

Sets the number of elements inside the buffer.

Parameters

  value | The number of elements to declare inside the buffer.

## ◆ setUsage()

virtual void nkGraphics::Buffer::setUsage | ( | BUFFER_USAGE | value | ) |
| pure virtual

Sets the usage flag in the buffer.

Parameters

  value | The usage flag to declare.

Remarks
  Not to be confused with declaring what usage will be done within the API with the buffer.

## ◆ setBindFlag()

virtual void nkGraphics::Buffer::setBindFlag | ( | BUFFER_BIND_FLAG | value | ) |
| pure virtual

Sets the binding flags for the buffer.

Parameters

  value | The binding flag to declare.

## ◆ setCpuAccessFlag()

virtual void nkGraphics::Buffer::setCpuAccessFlag | ( | BUFFER_CPU_ACCESS_FLAG | value | ) |
| pure virtual

Sets the cpu access flags for the buffer.

Parameters

  value | The value to declare.

## ◆ setMiscFlag()

virtual void nkGraphics::Buffer::setMiscFlag | ( | RESOURCE_MISC_FLAG | value | ) |
| pure virtual

Sets the misc flags for the buffer.

Parameters

  value | The value to declare.

## ◆ copyParams()

virtual void nkGraphics::Buffer::copyParams | ( | const Buffer & | other | ) |
| virtual

Copies the parameters from another buffer.

Parameters

  other | The buffer to copy the parameters from.

## ◆ map()

virtual MapResult nkGraphics::Buffer::map | ( | const MapRequestDescriptor & | requestDesc | ) |
| pure virtual

Maps the buffer. This allows to read or write the GPU data from the cpu context. For a read request, depending on the usage and CPU access flag, this can trigger staging buffer creation and copy to pull data from the GPU. Note that in some cases, this means a flush in the GPU pipeline (and a CPU lock) to ensure the latest data is retrieved.

Parameters

  requestDesc | The description of what kind of mapping is needed.

Returns
  The resulting mapped memory, if the request is valid. If not, reason will be logged, and mapped memory will be nullptr.

Remarks
  At all times, a buffer can only be mapped once. Be sure to call unmap() once the map handle is not necessary anymore.

## ◆ unmap()

virtual void nkGraphics::Buffer::unmap | ( | const UnmapRequestDescriptor & | requestDesc | ) |
| pure virtual

Requests to unmap the buffer. Should be called the earliest possible after a call to map().

Parameters

  requestDesc | The description of the unmap request.

## ◆ gpuCopyFrom()

virtual void nkGraphics::Buffer::gpuCopyFrom | ( | Buffer & | other,
|  | const ResourceGpuCopyDescriptor & | descriptor
| ) |  |
| pure virtual

Copy memory from one buffer to another. This will trigger copies on GPU, and involve the CPU the least possible.

Parameters

  other | The buffer to copy from.
  descriptor | The description of what kind of copy is wanted.

Remarks
  Special care needs to be taken to ensure that a copy is possible between both resources.

## ◆ prepareForShaderResourceUsage()

virtual void nkGraphics::Buffer::prepareForShaderResourceUsage | ( | bool | value = `true` | ) |
| virtual

Prepares the resource for an usage as a shader resource. This is needed to use the buffer in a Shader::addTexture() call.

Parameters

  value | If the buffer should be usable in such context (true) or not (false).

## ◆ prepareForComputeResourceUsage()

virtual void nkGraphics::Buffer::prepareForComputeResourceUsage | ( | bool | value = `true` | ) |
| virtual

Prepares the resource for an usage as a compute resource. This is needed to use the buffer in a Shader::addUavBuffer() call.

Parameters

  value | If the buffer should be usable in such context (true) or not (false).

## ◆ prepareForOutputStreamUsage()

virtual void nkGraphics::Buffer::prepareForOutputStreamUsage | ( | bool | value = `true` | ) |
| virtual

Prepares the resource for an usage as an output stream resource. This is needed to use the buffer in a Renderer::launchGeometryShaderStream() call.

Parameters

  value | If the buffer should be usable in such context (true) or not (false).

## ◆ exportClassToTree()

virtual void nkGraphics::Buffer::exportClassToTree | ( | nkExport::Node * | rootNode | ) |
| override virtual

Exports an item into a tree describing its structure and its data.

Parameters

  rootNode | The node into which the object has to write its related information.

Implements nkExport::Exportable.

## ◆ importClassFromTree()

virtual void nkGraphics::Buffer::importClassFromTree | ( | nkExport::Node * | rootNode | ) |
| override virtual

Imports information from a tree which is supposed to describe its structure and data.

Parameters

  rootNode | The root node of the tree holding the information.

Implements nkExport::Exportable.

## ◆ operator=()

Buffer& nkGraphics::Buffer::operator= | ( | const Buffer & |  | ) |
| delete

Copy assignment.

## ◆ create()

static nkMemory::UniquePtr<Buffer> nkGraphics::Buffer::create | ( | System * | system = `nullptr` | ) |
| static

Creates a standalone resource, linking it to a system, but no manager. This method can be used to allocate a resource and manually manage its lifetime.

Parameters

  system | The system to create the resource into. If left to nullptr, then the Singleton instance will be used.

Returns
  The created resource instance.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsGraphics/Buffers/Buffer.h